#pragma once

#include "camera_manage_type.h"
#include "cbb_camera_comm.h"
#include "cbb_enc_api.h"
#include "cbb_enc_type.h"
#include <memory>
#include <vector>
class EncoderManager {
  public:
    EncoderManager();
    ~EncoderManager();

    bool initializeEncoders(int cameraId, const std::vector<EncoderConfig> &configs);
    bool encodeFrame(int cameraId, const CbbCameraFrame_t &frame, std::vector<CbbEncoderRes_t> &results);
    void destroyEncoders(int cameraId);
    bool updateEncoderConfig(int cameraId, size_t encoderIndex, const EncoderConfig &newConfig);

  private:
    struct EncoderInstance {
        EncoderHandle handle;
        EncoderConfig config;

        EncoderInstance(EncoderHandle h, const EncoderConfig &c) : handle(h), config(c) {}
    };

    std::vector<std::vector<EncoderInstance>> m_encoders;
    bool applyEncoderConfig(EncoderHandle handle, const CbbEncoderConf_t &config);
    CbbEncoderConf_t convertToCbbEncoderConf(const EncoderConfig &config);
};